def isPrime(j):
    if j == 1: return False
    test = True
    m = j - 1
    while m >1:
        if not j % m:
            test = False
            break
        m -= 1
    return test

n = input()
r = []
for i in range (len(n)):
    for m in range(i + 1,len(n) +1):
        j = int(n[i:m])
        if isPrime(m):
            r += [j]
print  (max(r) if r else 0)